package com.pureut.order.dubbo;

import com.pureut.order.service.OrderSupplierManagementService;
import com.sale.common.core.domain.R;
import com.sale.common.core.utils.BeanCopyUtils;
import com.sale.order.api.RemoteSupplierService;
import com.sale.order.api.dto.CustomerBalance;
import com.sale.order.api.dto.OrderSupplierManagementDto;
import com.sale.system.api.RemoteCodeService;
import lombok.RequiredArgsConstructor;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * 供应商dubbo
 */
@RequiredArgsConstructor
@DubboService
@Service
public class RemoteSupplierServiceImpl implements RemoteSupplierService {

    private final OrderSupplierManagementService orderSupplierManagementService;


    /**
     * 获取供应商详情
     * @param id
     * @return
     */
    @Override
    public R<OrderSupplierManagementDto> view(Long id) {
        com.pureut.order.dto.OrderSupplierManagementDto supplierById = orderSupplierManagementService.getSupplierById(id);
        OrderSupplierManagementDto orderSupplierManagementDto = new OrderSupplierManagementDto();
        BeanCopyUtils.copy(supplierById,orderSupplierManagementDto);
        return R.ok(orderSupplierManagementDto);
    }

    /**
     * 通过编码获取供应商详情
     * @param code
     * @return
     */
    @Override
    public R<OrderSupplierManagementDto> getSupplierByCode(String code) {
        com.pureut.order.dto.OrderSupplierManagementDto supplierByCode = orderSupplierManagementService.getSupplierByCode(code);
        OrderSupplierManagementDto orderSupplierManagementDto = new OrderSupplierManagementDto();
        BeanUtils.copyProperties(supplierByCode,orderSupplierManagementDto);
        return R.ok(orderSupplierManagementDto);
    }

    /**
     *  获取启用供应商（财务模块调用）
     * @return
     */
    @Override
    public Map<String, String> getOpenSupplierFinance() {
        return orderSupplierManagementService.getOpenSupplierFinance();
    }

    /**
     * 通过供应商名称获取供应商编码(财务模块使用)
     */
    @Override
    public String getCodeBySupplierName(String supplierName) {
        return orderSupplierManagementService.getCodeBySupplierName(supplierName);
    }

    /**
     * 更新供应商余额(财务模块使用)
     */
    @Override
    public boolean updateSupplierBalance(CustomerBalance customer) {
        return orderSupplierManagementService.updateSupplierBalance(customer);
    }
}
